/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.myapp.struts;

import com.myapp.beans.StudentExamFormBean;
import com.myapp.biz.SurveyBiz;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.swing.JOptionPane;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author BAOBAO
 */
public class StudentExamAction extends org.apache.struts.action.Action {
    
    /* forward name="success" path="" */
   
    
    /**
     * This is the action called from the Struts framework.
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @throws java.lang.Exception
     * @return
     */
    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        StudentExamFormBean studentExamForm=(StudentExamFormBean)form;
        String[] strAnswer=studentExamForm.getAnswers();
        ArrayList<String> arr=new ArrayList<String>();
        for (int i = 0; i < strAnswer.length; i++) {
            arr.add(strAnswer[i]);
        }
        SurveyBiz surBiz=new SurveyBiz();
        int surveyId=Integer.parseInt(studentExamForm.getSurveyId());
        surBiz.updateElement(arr,this.getServlet().getServletContext().getRealPath("/"),"surveys.xml","/question/answer",surveyId);
        String content=studentExamForm.getComment();
        surBiz.creatComment(this.getServlet().getServletContext().getRealPath("/")+"/surveys.xml", surveyId, "5",content);
         
        return mapping.findForward("studentExam");

    }
}
